﻿var $bsTableSongPackage = $("#bsTableSongPackage");
var $bsTableFirstAuditingContent = $("#bsTableFirstAuditingContent");
var $bsTableFirstAuditingContent2 = $("#bsTableFirstAuditingContent2");
var $bsTableScoreSettings = $("#bsTableScoreSettings");
var $bsTableScoreSettings2 = $("#bsTableScoreSettings2");
$(function () {
    //其他媒体
    otherNoticeMediaClick();
    $("#cbNoticeMediaList_1").click(otherNoticeMediaClick);

    //公告媒体列表复选框
    NoticeMediaClick();
    $("input[name='cbNoticeMediaList']").click(NoticeMediaClick);

    //其他专家库
    OtherExpertLibClick();
    $("#cbExpertLib_1").click(OtherExpertLibClick);

    //专家库复选框单击事件
    ExpertLibClick();
    $("input[name='cbExpertLib']").click(ExpertLibClick);

    //表单验证
    var rules = {
        ProjectNameValue: {
            required: true
        },
        ProjectCodeValue: {
            required: true
        },
        JudgePersonCount: {
            digits: true
        },
        PurchasePersonCount: {
            digits: true
        },
        SongPackageNo: {
            digits: true
        }
    };
    FormValidation.BasicValidation(rules);

    //加载子包列表
    $bsTableSongPackage.bootstrapTable({
        url: "/ProjectSongPackage/GetList",
        pagination: false,
        singleSelect: true,//复选框只能选中一个
        clickToSelect: true,//单击行勾选复选框
        queryParams: queryParams
    });

    //加载符合性审查内容列表
    $bsTableFirstAuditingContent.bootstrapTable({
        url: "/FirstAuditingContent/GetList?auditingType=1",
        pagination: false,
        singleSelect: true,//复选框只能选中一个
        clickToSelect: true,//单击行勾选复选框
        queryParams: queryParams
    });
    //加载符合性审查内容列表
    $bsTableFirstAuditingContent2.bootstrapTable({
        url: "/FirstAuditingContent/GetList?auditingType=2",
        pagination: false,
        singleSelect: true,//复选框只能选中一个
        clickToSelect: true,//单击行勾选复选框
        queryParams: queryParams
    });

    //加载技术响应性评分
    $bsTableScoreSettings.bootstrapTable({
        url: "/ScoreSettings/GetList?scoreType=1",
        pagination: false,
        singleSelect: true,//复选框只能选中一个
        clickToSelect: true,//单击行勾选复选框
        queryParams: queryParams
    });

    //加载商务响应性评分
    $bsTableScoreSettings2.bootstrapTable({
        url: "/ScoreSettings/GetList?scoreType=2",
        pagination: false,
        singleSelect: true,//复选框只能选中一个
        clickToSelect: true,//单击行勾选复选框
        queryParams: queryParams
    });

    //添加子包showProjectFirstAuditingContent
    $("#addProjectSongPackage").click(function () {
        showProjectSongPackage("/ProjectSongPackage/Create?projectId=" + tempProjectInfoId, '添加');
    });

    //添加符合性审查内容
    $("#addFirstAuditingContent").click(function () {
        showFirstAuditingContent("/FirstAuditingContent/Create?auditingType=1&projectId=" + tempProjectInfoId, '添加',"1");
    });

    //添加资格审查内容
    $("#addFirstAuditingContent2").click(function () {
        showFirstAuditingContent("/FirstAuditingContent/Create?auditingType=2&projectId=" + tempProjectInfoId, '添加',"2");
    });

    //添加技术响应性评分
    $("#addScoreSettings").click(function () {
        showScoreSettings("/ScoreSettings/Create?scoreType=1&projectId=" + tempProjectInfoId,'添加','1');
    });

    //添加商务响应性评分
    $("#addScoreSettings2").click(function () {
        showScoreSettings("/ScoreSettings/Create?scoreType=2&projectId=" + tempProjectInfoId, '添加', '2');
    });
});


layui.laydate.render({ elem: '#FileEditTime' });
layui.laydate.render({ elem: '#NoticePublishTime' });
layui.laydate.render({ elem: '#NoticeStartTime' });
layui.laydate.render({ elem: '#NoticeEndTime' });
layui.laydate.render({ elem: '#NoticeSaleStartTime' });
layui.laydate.render({ elem: '#NoticeSaleEndTime' });
layui.laydate.render({ elem: '#SendFileDate' });
layui.laydate.render({ elem: '#SendFileStartTime', type: 'time', format: 'H时m分' });
layui.laydate.render({ elem: '#SendFileEndTime', type: 'time', format: 'H时m分' });

//初始化其他媒体文本框
function otherNoticeMediaClick() {
    var otherNoticeMedia = $("#cbNoticeMediaList_1").attr("checked");
    if (otherNoticeMedia == "checked") {
        $("#OtherNoticeMedia").show();
    } else {
        $("#OtherNoticeMedia").val("").hide();
    }
}

//公告媒体列表复选框单击事件
function NoticeMediaClick() {
    var noticeMediaListVal = [];
    $("input[name='cbNoticeMediaList']:checked").each(function () {
        var val = $(this).val();
        if (val != "1") {
            noticeMediaListVal.push(val);
        }
    });
    $("#NoticeMediaList").val(noticeMediaListVal.toString());
}

//初始化其他专家库文本框
function OtherExpertLibClick() {
    var otherExpertLib = $("#cbExpertLib_1").attr("checked");
    if (otherExpertLib == "checked") {
        $("#OtherExpertLib").show();
    } else {
        $("#OtherExpertLib").val("").hide();
    }
}

//专家库列表复选框单击事件
function ExpertLibClick() {
    var expertLibListVal = [];
    $("input[name='cbExpertLib']:checked").each(function () {
        var val = $(this).val();
        if (val != "1") {
            expertLibListVal.push(val);
        }
    });
    $("#ExpertLib").val(expertLibListVal.toString());
}


function SearchSongPackage() {
    $bsTableSongPackage.bootstrapTable("refreshOptions", {
        pageNumber: 1,
        queryParams: queryParams
    });
}

function SearchFirstAuditingContent() {
    $bsTableFirstAuditingContent.bootstrapTable("refreshOptions", {
        pageNumber: 1,
        queryParams: queryParams
    });
}

function SearchFirstAuditingContent2() {
    $bsTableFirstAuditingContent2.bootstrapTable("refreshOptions", {
        pageNumber: 1,
        queryParams: queryParams
    });
}

function SearchScoreSettings() {
    $bsTableScoreSettings.bootstrapTable("refreshOptions", {
        pageNumber: 1,
        queryParams: queryParams
    });
}

function SearchScoreSettings2() {
    $bsTableScoreSettings2.bootstrapTable("refreshOptions", {
        pageNumber: 1,
        queryParams: queryParams
    });
}

function queryParams(params) {
    return {
        projectId: tempProjectInfoId
    };
}



function editFirstAuditingContentFormatter(value, row, index) {
    return '<a href="javascript:void(0);" onclick="showFirstAuditingContent(\'/FirstAuditingContent/Edit/' + value + '\',\'修改\','+row.AuditingType+')" class="btn btn-xs green"><i class="fa fa-edit"></i> 修改 </a>';
}

function editScoreSettingsFormatter(value, row, index) {
    return '<a href="javascript:void(0);" onclick="showScoreSettings(\'/ScoreSettings/Edit/' + value + '\',\'修改\','+row.ScoreType+')" class="btn btn-xs green"><i class="fa fa-edit"></i> 修改 </a>';
}


//打开子包页面
function showProjectSongPackage(url, title) {
    layer.open({
        type: 2,
        title: title+"子包",
        area: ["500px", "301px"],
        content: [url, 'no']
    });
}

//打开符合性审查内容页面
function showFirstAuditingContent(url, title, auditingType) {
    var h = "300px";
    if (title == "修改") {
        h = "225px";
    }
    if (auditingType == 1) {
        title = title + "符合性审查内容"
    } else {
        title = title + "资格审查内容"
    }
   
    layer.open({
        type: 2,
        title: title,
        area: ["500px", h],
        content: [url, 'no']
    });
}

//打开评分设置
function showScoreSettings(url, title, scoreType) {

    if (scoreType == 1) {
        title = title + "技术响应性评分"
    } else {
        title = title + "商务响应性评分"
    }
    
    layer.open({
        type: 2,
        title: title,
        area: ["500px", "528px"],
        content: [url, 'no']
    });
}

//预留评分
function showReserveScoreSettings(projectId, scoreType) {
    var title = "";
    if (scoreType == 3) {
        title = "预留部分权限1设置"
    } else {
        title = "预留部分权限2设置"
    }
    layer.open({
        type: 2,
        title: title,
        area: ["90%", "95%"],
        content: ["/ScoreSettings/Index?projectId=" + projectId + "&scoreType=" + scoreType, 'no']
    });
}

//复制子包
function copySongPackage(songPackageId, projectId) {
    layer.open({
        type: 2,
        title: "复制子包评分规则",
        area: ["300px", "220px"],
        content: ["/ScoreSettings/CopySongPackage?songPackageId=" + songPackageId + "&projectId=" + projectId, 'no']
    });
}